home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / Clueless.swf / scripts / Model.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  13.0 KB  |  477 lines

  1. package
  2. {
  3.    import flash.display.*;
  4.    import flash.filters.BitmapFilter;
  5.    import flash.filters.ColorMatrixFilter;
  6.    import flash.geom.Point;
  7.    import flash.utils.Dictionary;
  8.    
  9.    [Embed(source="/_assets/assets.swf", symbol="Model")]
  10.    public class Model extends MovieClip
  11.    {
  12.       
  13.       public static const NUM_LAYERS:int = 12;
  14.        
  15.       
  16.       internal var _dMountPoints:Dictionary;
  17.       
  18.       internal var _dParts:Dictionary;
  19.       
  20.       internal var _sPose:String = "1";
  21.       
  22.       internal var _pComposePosition:Point;
  23.       
  24.       internal var _bActive:Boolean = true;
  25.       
  26.       internal var _aLayers:Array;
  27.       
  28.       internal var _partBra:Part = null;
  29.       
  30.       public function Model()
  31.       {
  32.          var _loc1_:int = 0;
  33.          var _loc2_:MovieClip = null;
  34.          _dMountPoints = new Dictionary();
  35.          _dParts = new Dictionary();
  36.          _aLayers = new Array();
  37.          _sPose = ModelPose.POSE_1;
  38.          _pComposePosition = new Point();
  39.          _partBra = null;
  40.          _bActive = true;
  41.          super();
  42.          while(numChildren > 0)
  43.          {
  44.             removeChildAt(0);
  45.          }
  46.          _loc1_ = 0;
  47.          while(_loc1_ < NUM_LAYERS)
  48.          {
  49.             _loc2_ = new MovieClip();
  50.             _loc2_.x = 0;
  51.             _loc2_.y = 0;
  52.             addChild(_loc2_);
  53.             _aLayers.push(_loc2_);
  54.             _loc1_++;
  55.          }
  56.       }
  57.       
  58.       public static function extractFromStage(param1:DisplayObjectContainer) : Array
  59.       {
  60.          var _loc2_:int = 0;
  61.          var _loc3_:Array = null;
  62.          var _loc4_:DisplayObject = null;
  63.          _loc2_ = 0;
  64.          _loc3_ = new Array();
  65.          _loc2_ = 0;
  66.          while(_loc2_ < param1.numChildren)
  67.          {
  68.             if((_loc4_ = param1.getChildAt(_loc2_)) is Model)
  69.             {
  70.                _loc3_.push(_loc4_);
  71.             }
  72.             _loc2_++;
  73.          }
  74.          _loc3_.sortOn("name");
  75.          return _loc3_;
  76.       }
  77.       
  78.       public function isAttributePresentInCategory(param1:String, param2:String) : Boolean
  79.       {
  80.          var _loc3_:Part = null;
  81.          for each(_loc3_ in _dParts)
  82.          {
  83.             if(_loc3_.Category.toLowerCase() == param2.toLowerCase() && _loc3_.Template.hasAttribute(param1))
  84.             {
  85.                return true;
  86.             }
  87.          }
  88.          return false;
  89.       }
  90.       
  91.       public function getPercentMatch(param1:Model) : Number
  92.       {
  93.          var _loc2_:int = 0;
  94.          var _loc3_:int = 0;
  95.          var _loc4_:Part = null;
  96.          _loc2_ = 0;
  97.          _loc3_ = 0;
  98.          for each(_loc4_ in _dParts)
  99.          {
  100.             if(_loc4_.Layer > 0)
  101.             {
  102.                if(_loc4_.isEqual(param1.getPart(_loc4_.Category)))
  103.                {
  104.                   _loc2_++;
  105.                }
  106.                _loc3_++;
  107.             }
  108.          }
  109.          if(getPose() == param1.getPose())
  110.          {
  111.             _loc2_++;
  112.          }
  113.          _loc3_++;
  114.          return _loc2_ / _loc3_;
  115.       }
  116.       
  117.       public function getPose() : String
  118.       {
  119.          return _sPose;
  120.       }
  121.       
  122.       public function setPose(param1:String) : void
  123.       {
  124.          var _loc2_:Part = null;
  125.          _sPose = param1;
  126.          for each(_loc2_ in _dParts)
  127.          {
  128.             if(_loc2_ != null)
  129.             {
  130.                _loc2_.Pose = _sPose;
  131.             }
  132.          }
  133.       }
  134.       
  135.       public function clearAllParts() : void
  136.       {
  137.          var _loc1_:Array = null;
  138.          var _loc2_:Part = null;
  139.          _loc1_ = new Array();
  140.          for each(_loc2_ in _dParts)
  141.          {
  142.             _loc1_.push(_loc2_);
  143.          }
  144.          for each(_loc2_ in _loc1_)
  145.          {
  146.             removePart(_loc2_.Category);
  147.          }
  148.       }
  149.       
  150.       public function get Active() : Boolean
  151.       {
  152.          return _bActive;
  153.       }
  154.       
  155.       public function getCommonAttributes(param1:String) : Array
  156.       {
  157.          var _loc2_:Array = null;
  158.          var _loc3_:Array = null;
  159.          var _loc4_:PartTemplate = null;
  160.          var _loc5_:int = 0;
  161.          var _loc6_:int = 0;
  162.          var _loc7_:Boolean = false;
  163.          var _loc8_:PartAttribute = null;
  164.          var _loc9_:PartTemplate = null;
  165.          _loc2_ = new Array();
  166.          _loc3_ = new Array();
  167.          if(getPart("dress") != null && getPart("shoe") != null)
  168.          {
  169.             _loc3_.push(getPart("dress").Template);
  170.             _loc3_.push(getPart("shoe").Template);
  171.          }
  172.          else
  173.          {
  174.             if(!(getPart("top") != null && getPart("bottom") != null && getPart("shoe") != null))
  175.             {
  176.                return _loc2_;
  177.             }
  178.             _loc3_.push(getPart("top").Template);
  179.             _loc3_.push(getPart("bottom").Template);
  180.             _loc3_.push(getPart("shoe").Template);
  181.          }
  182.          if(!(_loc4_ = _loc3_[0]).matchesTheme(param1))
  183.          {
  184.             return _loc2_;
  185.          }
  186.          _loc5_ = 0;
  187.          while(_loc5_ < _loc4_.Attributes.length)
  188.          {
  189.             _loc7_ = true;
  190.             if((_loc8_ = _loc4_.Attributes[_loc5_]).Score < 0)
  191.             {
  192.                _loc7_ = false;
  193.             }
  194.             if(param1.toLowerCase().indexOf(_loc8_.Name.toLowerCase()) != -1)
  195.             {
  196.                _loc7_ = false;
  197.             }
  198.             _loc6_ = 1;
  199.             while(_loc6_ < _loc3_.length)
  200.             {
  201.                if(!(_loc9_ = _loc3_[_loc6_]).hasAttribute(_loc8_.Name))
  202.                {
  203.                   _loc7_ = false;
  204.                }
  205.                _loc6_++;
  206.             }
  207.             if(_loc7_)
  208.             {
  209.                _loc2_.push(_loc8_.Name);
  210.             }
  211.             _loc5_++;
  212.          }
  213.          return _loc2_;
  214.       }
  215.       
  216.       public function getLayers() : Array
  217.       {
  218.          return _aLayers;
  219.       }
  220.       
  221.       public function addPart(param1:Part) : Part
  222.       {
  223.          var _loc2_:int = 0;
  224.          var _loc3_:Boolean = false;
  225.          var _loc4_:Part = null;
  226.          _loc2_ = 0;
  227.          _loc3_ = false;
  228.          _loc4_ = _dParts[param1.Category] as Part;
  229.          param1.Pose = this._sPose;
  230.          if(_loc4_ != null)
  231.          {
  232.             _aLayers[_loc4_.Layer].removeChild(_loc4_);
  233.          }
  234.          _dParts[param1.Category] = param1;
  235.          _aLayers[param1.Layer].addChild(param1);
  236.          switch(param1.Category)
  237.          {
  238.             case "top":
  239.                _loc3_ = true;
  240.             case "bottom":
  241.                removePart("dress",false);
  242.                break;
  243.             case "dress":
  244.                removePart("top",false);
  245.                removePart("bottom",false);
  246.                _loc3_ = true;
  247.                break;
  248.             case "bra":
  249.                _partBra = param1;
  250.                if(getPart("top") != null || getPart("dress") != null)
  251.                {
  252.                   _loc3_ = true;
  253.                }
  254.                break;
  255.             case "body":
  256.                if(_partBra != null)
  257.                {
  258.                   _aLayers[_partBra.Layer].addChild(_partBra);
  259.                }
  260.          }
  261.          if(_loc3_)
  262.          {
  263.             if(_partBra != null)
  264.             {
  265.                _partBra.visible = false;
  266.             }
  267.          }
  268.          updateTuckIns();
  269.          dispatchEvent(new ModelEvent(ModelEvent.MODEL_PART_CHANGED));
  270.          return _loc4_;
  271.       }
  272.       
  273.       public function calcScore(param1:Array) : int
  274.       {
  275.          var _loc2_:int = 0;
  276.          var _loc3_:String = null;
  277.          var _loc4_:Part = null;
  278.          _loc2_ = 0;
  279.          for each(_loc3_ in ["top","bottom","shoe","accessory"])
  280.          {
  281.             if((_loc4_ = getPart(_loc3_)) != null)
  282.             {
  283.                _loc2_ += _loc4_.Template.getScoreForList(param1);
  284.             }
  285.          }
  286.          return _loc2_;
  287.       }
  288.       
  289.       public function undress() : void
  290.       {
  291.          var _loc1_:Array = null;
  292.          var _loc2_:Part = null;
  293.          _loc1_ = new Array();
  294.          for each(_loc2_ in _dParts)
  295.          {
  296.             if(_loc2_.Layer != 0)
  297.             {
  298.                _loc1_.push(_loc2_);
  299.             }
  300.          }
  301.          for each(_loc2_ in _loc1_)
  302.          {
  303.             removePart(_loc2_.Category);
  304.          }
  305.       }
  306.       
  307.       public function set Active(param1:Boolean) : void
  308.       {
  309.          _bActive = param1;
  310.          if(_bActive)
  311.          {
  312.             dispatchEvent(new ModelEvent(ModelEvent.MODEL_ACTIVE_CHANGED));
  313.          }
  314.       }
  315.       
  316.       public function clone(param1:Model) : void
  317.       {
  318.          var _loc2_:Part = null;
  319.          clearAllParts();
  320.          for each(_loc2_ in param1._dParts)
  321.          {
  322.             addPart(_loc2_.Template.createPart());
  323.          }
  324.          _pComposePosition = new Point(param1._pComposePosition.x,param1._pComposePosition.y);
  325.          if(param1.getPart("bra") != null)
  326.          {
  327.             addPart(param1.getPart("bra").Template.createPart());
  328.          }
  329.          setPose(param1.getPose());
  330.       }
  331.       
  332.       public function getPart(param1:String) : Part
  333.       {
  334.          return _dParts[param1] as Part;
  335.       }
  336.       
  337.       public function set ComposePosition(param1:Point) : *
  338.       {
  339.          _pComposePosition = new Point(param1.x,param1.y);
  340.       }
  341.       
  342.       protected function updateTuckIns() : void
  343.       {
  344.          var _loc1_:Part = null;
  345.          var _loc2_:String = null;
  346.          for each(_loc2_ in ["top","bottom"])
  347.          {
  348.             _loc1_ = getPart(_loc2_);
  349.             if(_loc1_ != null)
  350.             {
  351.                _loc1_.updateTuckIn();
  352.             }
  353.          }
  354.       }
  355.       
  356.       public function removePart(param1:String, param2:Boolean = true) : Part
  357.       {
  358.          var _loc3_:Part = null;
  359.          _loc3_ = _dParts[param1] as Part;
  360.          delete _dParts[param1];
  361.          if(_loc3_ != null)
  362.          {
  363.             _aLayers[_loc3_.Layer].removeChild(_loc3_);
  364.             if(param1 == "top" || param1 == "dress")
  365.             {
  366.                _partBra.visible = true;
  367.             }
  368.             dispatchEvent(new ModelEvent(ModelEvent.MODEL_PART_CHANGED));
  369.          }
  370.          updateTuckIns();
  371.          return _loc3_;
  372.       }
  373.       
  374.       public function pickupPart(param1:Point, param2:DisplayObjectContainer) : Part
  375.       {
  376.          var _loc3_:Part = null;
  377.          var _loc4_:Part = null;
  378.          var _loc5_:DisplayObjectContainer = null;
  379.          var _loc6_:* = undefined;
  380.          _loc3_ = null;
  381.          for each(_loc4_ in _dParts)
  382.          {
  383.             if(_loc4_ != null)
  384.             {
  385.                if(_loc4_.hasPixel(param1.x,param1.y,param2) && _loc4_.Layer > 0)
  386.                {
  387.                   if(_loc3_ == null)
  388.                   {
  389.                      _loc3_ = _loc4_;
  390.                   }
  391.                   else if(_loc4_.Layer > _loc3_.Layer)
  392.                   {
  393.                      _loc3_ = _loc4_;
  394.                   }
  395.                }
  396.             }
  397.          }
  398.          if(_loc3_ != null)
  399.          {
  400.             _loc5_ = null;
  401.             _loc5_ = _loc3_.parent;
  402.             do
  403.             {
  404.                _loc6_ = _loc5_.localToGlobal(new Point(0,0));
  405.                _loc3_.x = _loc6_.x;
  406.                _loc3_.y = _loc6_.y;
  407.             }
  408.             while((_loc5_ = _loc5_.parent) != param2);
  409.             
  410.             removePart(_loc3_.Category);
  411.             _loc3_.Pose = ModelPose.DEFAULT;
  412.          }
  413.          return _loc3_;
  414.       }
  415.       
  416.       protected function dumpFilters() : void
  417.       {
  418.          var _loc1_:BitmapFilter = null;
  419.          var _loc2_:ColorMatrixFilter = null;
  420.          if(filters != null)
  421.          {
  422.             for each(_loc1_ in filters)
  423.             {
  424.                trace(_loc1_);
  425.                if(_loc1_ is ColorMatrixFilter)
  426.                {
  427.                   trace("ColorMatrixFilter");
  428.                   _loc2_ = _loc1_ as ColorMatrixFilter;
  429.                   trace(_loc2_.matrix);
  430.                }
  431.             }
  432.          }
  433.       }
  434.       
  435.       public function isDressed() : Boolean
  436.       {
  437.          if(this.getPart("top") != null && this.getPart("bottom") != null && this.getPart("shoe") != null || this.getPart("dress") != null && this.getPart("shoe") != null)
  438.          {
  439.             return true;
  440.          }
  441.          return false;
  442.       }
  443.       
  444.       public function get ComposePosition() : Point
  445.       {
  446.          return _pComposePosition;
  447.       }
  448.       
  449.       public function hasPart(param1:Part) : Boolean
  450.       {
  451.          var _loc2_:Part = null;
  452.          _loc2_ = getPart(param1.Category);
  453.          if(_loc2_ != null)
  454.          {
  455.             if(_loc2_.Template == param1.Template)
  456.             {
  457.                return true;
  458.             }
  459.          }
  460.          return false;
  461.       }
  462.       
  463.       public function isAttributePresent(param1:String) : Boolean
  464.       {
  465.          var _loc2_:Part = null;
  466.          for each(_loc2_ in _dParts)
  467.          {
  468.             if(_loc2_.Template.hasAttribute(param1))
  469.             {
  470.                return true;
  471.             }
  472.          }
  473.          return false;
  474.       }
  475.    }
  476. }
  477.